package com.windystory.wslibrary.ui.imageview;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Xfermode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.util.AttributeSet;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.windystory.wslibrary.R;

/**
 * imageViewX
 */
public class ImageViewX {

    //正常类型
    private final int NORMAL = 0;

    //圆类型
    private final int CIRCLE = 1;

    //圆角类型
    private final int CIRCLE_TRI = 2;

    /**
     * 设置圆角
     *
     * @param activity
     * @param imgURL
     * @param errorImg
     * @param imageView
     */
    public static void setImageCircle(Activity activity, String imgURL, int errorImg, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .error(errorImg)
                .bitmapTransform(new CircleCrop());
        Glide.with(activity).load(imgURL).apply(options).into(imageView);
    }

    /**
     * 设置圆角
     *
     * @param activity
     * @param imgURL
     * @param errorImg
     * @param imageView
     */
    public static void setImageCircle(Activity activity, int imgURL, int errorImg, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .error(errorImg)
                .bitmapTransform(new CircleCrop());
        Glide.with(activity).load(imgURL).apply(options).into(imageView);
    }


    /**
     * 设置圆角矩形
     *
     * @param activity
     * @param imgURL
     * @param errorImg
     * @param imageView
     */
    public static void setImageRoundedCorners(Activity activity, String imgURL, int errorImg, ImageView imageView, int roundingRadius) {
        if (roundingRadius < 15) {
            roundingRadius = 15;
        }
        RequestOptions options = new RequestOptions()
                .error(errorImg)
                .bitmapTransform(new RoundedCorners(roundingRadius));
        Glide.with(activity).load(imgURL).apply(options).into(imageView);
    }

    /**
     * 设置圆角矩形
     *
     * @param activity
     * @param imgURL
     * @param errorImg
     * @param imageView
     */
    public static void setImageRoundedCorners(Activity activity, int imgURL, int errorImg, ImageView imageView, int roundingRadius) {
        if (roundingRadius < 15) {
            roundingRadius = 15;
        }
        RequestOptions options = new RequestOptions()
                .error(errorImg)
                .bitmapTransform(new RoundedCorners(roundingRadius));
        Glide.with(activity).load(imgURL).apply(options).into(imageView);
    }


}
